/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Ok3w_Article",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.MyTable.IServices;
using System.Collections;
using VOL.Core.DBManager;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using VOL.Core.Filters;
using VOL.Core.Utilities;
using VOL.Core.ManageUser;

namespace VOL.MyTable.Controllers
{
    public partial class Ok3w_ArticleController
    {
        private readonly IOk3w_ArticleService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Ok3w_ArticleController(
            IOk3w_ArticleService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
      /*  [DisableRequestSizeLimit]
        public override IActionResult Upload(IEnumerable<IFormFile> fileInput)
        {
            return base.Upload(fileInput);
        }*/
        [HttpPost, Route("GetPageData"),AllowAnonymous]
        [ApiActionPermission()]
        public override ActionResult GetPageData([FromBody] PageDataOptions loadData)
        {

            return base.GetPageData(loadData);
        }

        [HttpPost, Route("get_ok3w_for_front"), AllowAnonymous]//传数据给前端 map 
        public dynamic get_ok3w_for_front(Guid qid,string lstype)
        {

           /* Sys_User user = DBServerProvider.DbContext.Set<Sys_User>().Where(x => x.UserName == "admin")
                    .FirstOrDefault();
            string token = JwtHelper.IssueJwt(new UserInfo()
            {
                User_Id = user.User_Id,
                UserName = user.UserName,
                Role_Id = user.Role_Id
            });
            user.Token = token;
            DBServerProvider.DbContext.Update(user);
            DBServerProvider.DbContext.SaveChanges();
           // UserContext.Current.LogOut(user.User_Id);*/

            Hashtable rtn_hst = new Hashtable();

            List<Ok3w_Article> ok3W_Article_list = DBServerProvider.DbContext.Set<Ok3w_Article>().ToList();
            List<Ok3w_Class> Ok3w_Class_list = DBServerProvider.SqlDapper.QueryList<Ok3w_Class>("select * from Ok3w_Class","").ToList();
            var rnttable = from q in ok3W_Article_list
                           join q2 in Ok3w_Class_list on q.ClassID equals q2.id
                           select new
                           {
                               q2.SortName,
                               q,

                           };
            List<dynamic> online_class_list = DBServerProvider.SqlDapper.QueryList<dynamic>("select distinct a.SortName text from Ok3w_Class a,Ok3w_Article b where b.ClassID=a.id", "").ToList();
            if (lstype=="all")
            {
                rtn_hst.Add("alltable", rnttable);
            }
            else
            {
                rnttable = rnttable.Where(w => w.q.ok3w_article_id == qid).AsQueryable();
                rtn_hst.Add("alltable", rnttable);
            }
            List<dynamic> tree_data = DBServerProvider.SqlDapper.QueryList<dynamic>(" select sortname name,id,parentid parentId,id classid from ok3w_class", "").ToList();

           
            rtn_hst.Add("online_class_list", online_class_list);
            rtn_hst.Add("tree_data", tree_data);
            return rtn_hst;
        }
    }
}
